{extend name="base/form_base" /}
{block name="content"}
<form class="layui-form" id="ajaxform" onsubmit="return false">
  <input type="hidden" name="id" value="{$data.id ?? ''}">
  <div class="layui-form-item">
    <label class="layui-form-label">通稿标题：</label>
    <div class="layui-input-block">
      <input name="title" required="" lay-verify="required" autocomplete="off" class="layui-input" type="text" id='title' value="{$data.title ?? ''}">
    </div>
    <div class="layui-form-mid layui-word-aux"></div> 
  </div>
    <div class="layui-form-item">
    <label class="layui-form-label">封面：</label>
    <div class="layui-input-inline">
        <img src="{$data.pic ?? ''}" style="width: 100px;height: 100px" id="show_upload_img">
        <input type="hidden" name="pic" id='pic' value="{$data.pic ?? ''}">
     </div>
  </div>
  <div class="layui-form-item">
    <div class="layui-input-block">
      <button type="button" class="layui-btn" id="upload">
        <i class="layui-icon"></i>上传图片
      </button>
    </div>
  </div>
    <div class="layui-form-item layui-form-text">
    <label class="layui-form-label">简介</label>
    <div class="layui-input-block">
      <textarea name="ms" placeholder="请输入内容" class="layui-textarea">{$data.ms ?? ''}</textarea>
    </div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label">正文：</label>
  </div>
   <div class="layui-input-block">
    <textarea id="demo" style="display: none;" name='content'>{$data.content ?? ''}</textarea>
  </div>
  <div class="site-demo-button" style="margin-top: 20px;">
    <button class="layui-btn site-demo-layedit" data-type="ajax">立即提交</button>
  </div>
</form>
{/block}
{block name="script"}
<script>
layui.use(['form', 'layedit','upload'], function(){
  var layedit = layui.layedit;
  var form = layui.form;
    var upload = layui.upload;
  layedit.set({
      uploadImage: {
        url: '{:C("system_url")}/api/Upload/upload_img2'
        ,type: 'post' //默认post
      }
    });
  var text = layedit.build('demo',{
    height: 500 //设置编辑器高度
  }); //建立编辑器
  //编辑器外部操作
  var active = {
    ajax: function(){
      layedit.sync(text);
      var post_data = $("#ajaxform").serialize();
      $.ajax({
            url:"{:url('admin/community/editAnnounce')}",
            type:"POST",
            data:post_data,
            success:function(ret){
                if (ret.code == 0) {
                  window.location.reload();
                  parent.$(".layui-laypage-btn")[0].click();
                }
                if (ret.code == 1) {
                    layer.msg(ret.msg);
                }
            }
        });
    }
  };
  $('.site-demo-layedit').on('click', function(){
    var type = $(this).data('type');
    active[type] ? active[type].call(this) : '';
  });
  upload.render({
  elem: '#upload'
  ,url: '{:C("system_url")}/api/Upload/upload_img'
  ,before:function(){
    var index = layer.msg('正在拼命处理...' , {
      icon: 16 ,
      shade: 0.6 ,
      time: 0 ,
    });
  }
  ,done: function(res){
    if(res.code==0){
      $("#show_upload_img").attr('src',res.data);
       $("#pic").val(res.data);
      layer.msg('上传图片成功');
    } else {
      layer.msg('上传图片失败');
    }
  }
  }); 
});
</script>
{/block}